<template>
  <div class="guess-you-like-contaner">
    <div class="title">你可能还喜欢</div>
    <!-- 容器包裹 -->
    <div class="swiper-content">
      <Swiper
        class="cover"
        :showArrow="false"
        :autoplay="true"
        indicatorColor="#cecece"
        indicatorActiveColor="#a7936e"
        :interval="3000">
        <SwiperItem v-for="(block, index) in repeatList" :key="index">
          <div class="goods-container">
            <div class="goods" v-for="item in block" :key="item.id">
              <!-- 商品图片 -->
              <div class="goods-pic">
                <img class="transition" v-lazy="item.url" />
              </div>
              <!-- 商品标签 -->
              <div class="prd-tags"><span class="tag" v-for="(tag, tagIndex) in item.tags" :key="tagIndex">{{tag}}</span></div>
              <div class="goods-name">{{ item.name }}</div>
              <div class="price">{{$t('priceSymbol')}}{{item.price | price}} <span class="iconfont icon-gouwuche"></span></div>
            </div>
          </div>
        </SwiperItem>
      </Swiper>
    </div>
  </div>
</template>

<script>
export default {
  data () {
    return {
      // 原始数据
      list: [
        { id: 1, url: 'http://yanxuan.nosdn.127.net/cc56e07680a6848c15ffeb46997c0d11.png?imageView&quality=95&thumbnail=210x210', name: '男式精梳棉条纹短袖T恤衫', price: 7900, originPrice: 15700 },
        { id: 2, url: 'http://yanxuan.nosdn.127.net/cc56e07680a6848c15ffeb46997c0d11.png?imageView&quality=95&thumbnail=210x210', name: '男式精梳棉条纹短袖T恤衫', price: 7900, originPrice: 15700 },
        { id: 3, url: 'http://yanxuan.nosdn.127.net/cc56e07680a6848c15ffeb46997c0d11.png?imageView&quality=95&thumbnail=210x210', name: '男式精梳棉条纹短袖T恤衫', price: 7900, originPrice: 15700, tags: ['舒服'] },
        { id: 4, url: 'http://yanxuan.nosdn.127.net/cc56e07680a6848c15ffeb46997c0d11.png?imageView&quality=95&thumbnail=210x210', name: '男式精梳棉条纹短袖T恤衫', price: 900, originPrice: 5700 },
        { id: 5, url: 'http://yanxuan.nosdn.127.net/cc56e07680a6848c15ffeb46997c0d11.png?imageView&quality=95&thumbnail=210x210', name: '男式精梳棉条纹短袖T恤衫', price: 7900, originPrice: 15700 },
        { id: 6, url: 'http://yanxuan.nosdn.127.net/cc56e07680a6848c15ffeb46997c0d11.png?imageView&quality=95&thumbnail=210x210', name: '男式精梳棉条纹短袖T恤衫', price: 7900, originPrice: 15700, tags: ['好吃'] },
        { id: 7, url: 'http://yanxuan.nosdn.127.net/cc56e07680a6848c15ffeb46997c0d11.png?imageView&quality=95&thumbnail=210x210', name: '男式精梳棉条纹短袖T恤衫', price: 7900, originPrice: 15700 },
        { id: 8, url: 'http://yanxuan.nosdn.127.net/cc56e07680a6848c15ffeb46997c0d11.png?imageView&quality=95&thumbnail=210x210', name: '男式精梳棉条纹短袖T恤衫', price: 700, originPrice: 1700 },
        { id: 9, url: 'http://yanxuan.nosdn.127.net/cc56e07680a6848c15ffeb46997c0d11.png?imageView&quality=95&thumbnail=210x210', name: '男式精梳棉条纹短袖T恤衫', price: 7900, originPrice: 15700 },
        { id: 10, url: 'http://yanxuan.nosdn.127.net/cc56e07680a6848c15ffeb46997c0d11.png?imageView&quality=95&thumbnail=210x210', name: '男式精梳棉条纹短袖T恤衫', price: 7900, originPrice: 15700 }
      ],
      // 处理之后的数据
      repeatList: []
    }
  },

  created () {
    // 当前索引值
    let index = 0
    // 处理之后的数据
    const list = []
    // 开始循环
    this.list.forEach(item => {
      // 如果当前没有数据，则开始创建一个空数组
      if (!list[index]) {
        list[index] = []
      }
      // 将数据塞到指定的位置上
      list[index].push(item)
      // 如果当前以及是4条数据了
      if (list[index].length === 4) {
        index++
      }
    })
    // 设置遍历的数据
    this.repeatList = list
  }
}
</script>

<style lang="less" scoped>
@import "../styles/variable.less";

.guess-you-like-contaner {
  border: 1px solid #e8e8e8;
  .title {
    background-color: #f5f5f5;
    font-size: 18px;
    height: 44px;
    line-height: 44px;
    text-indent: 18px;
  }
  .swiper-content {
    width: 930px;
    margin: 12px auto 0px;
    .cover {
      height: 338px;
    }
    .goods-container {
      overflow: hidden;
      .goods {
        float: left;
        width: 210px;
        height: 286px;
        text-align: center;
        margin-right: 30px;
        .goods-pic {
          width: 210px;
          height: 210px;
          overflow: hidden;
          img {
            width: 100%;
            height: 100%;
          }
          &:hover {
            img {
              transform: scale(1.06, 1.06);
            }
          }
        }
        .prd-tags {
          height: 20px;
          margin: 6px 0px 4px;
          .tag {
            background-color: @bg-tips;
            color: #ffffff;
            display: inline-block;
            font-size: 12px;
            padding: 0px 5px;
            height: 20px;
            line-height: 20px;
          }
        }
        .goods-name {
          color: @font-color;
          cursor: pointer;
          font-weight: bold;
          font-size: 14px;
          &:hover {
            color: @font-color-golden;
          }
        }
        .price {
          color: @color-warning;
          line-height: 22px;
          .iconfont {
            background-color: @bg-color-golden-light;
            border-radius: 12px;
            color: @font-color-golden;
            cursor: pointer;
            display: inline-block;
            font-size: 13px;
            width: 24px;
            height: 24px;
            line-height: 25px;
            text-align: center;
            margin-left: 6px;
          }
        }
        &:last-child {
          margin-right: 0px;
        }
      }
    }
  }
}
</style>
